package com.lagou.edu.pojo;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

/**
 * 响应结果
 */
public class Result implements BeanNameAware, BeanFactoryAware, ApplicationContextAware,
        InitializingBean, DisposableBean {

    private String status;
    private String message;

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        System.out.println("第2步 设置属性status: " + status);
        this.status = status;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        System.out.println("第2步 设置属性message: " + message);
        this.message = message;
    }

    @Override
    public String toString() {
        return "Result{" +
                "status='" + status + '\'' +
                ", message='" + message + '\'' +
                '}';
    }

    @Override
    public void setBeanName(String name) {
        System.out.println("第3步 BeanNameAware 注册我成为bean时定义的id: " + name);
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("第4步 BeanFactoryAware 管理我的beanFactory为: " + beanFactory);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("第5步 ApplicationContextAware 高级容器接口applicationContext: " + applicationContext);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("第7步 InitializingBean afterPropertiesSet...");
    }

    @PostConstruct
    public void postCoustrcut() {
        System.out.println("第8步1 postCoustrcut注解.....");
    }

    public void initMethod() {
        System.out.println("第8步2 初始化方法.....");
    }

    @PreDestroy
    public void preDestroy() {
        System.out.println("第11步1 PreDestroy注解......");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("第11步2 DisposableBean destroy......");
    }

    public void destroyMethod() {
        System.out.println("第11步3 销毁方法......");
    }

}
